package cn.fl.ref.asspackinfo.service.impl;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.dto.DataResultDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.framework.constant.DictionaryConstant;
import cn.fl.ref.asspackinfo.service.IAssPackInfoService;
import cn.fl.ref.asspackinfo.transform.AssPackInfoReplaceVOTransform;
import cn.fl.ref.asspackinfo.transform.AssPackInfoVOTransform;
import cn.fl.ref.asspackinfo.transform.AssPackListVOTransform;
import cn.fl.ref.asspackinfo.transform.FncPrjPayRltvInfoVOTransform;
import cn.fl.ref.asspackinfo.vo.*;
import fl.flow.facade.flow.dto.FlowStartParamsDTO;
import fl.ref.asspackinfo.condition.AssPackInfoQueryCondition;
import fl.ref.asspackinfo.condition.AssPackInfoReplaceQueryCondition;
import fl.ref.asspackinfo.constant.AssPackInfoConstant;
import fl.ref.asspackinfo.constant.AssPackInfoConstant.AssPackInfoMst;
import fl.ref.asspackinfo.dto.*;
import fl.ref.asspackinfo.service.IAssPackInfoApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class AssPackInfoServiceImpl implements IAssPackInfoService {

	private static final Logger logger = LoggerFactory.getLogger(AssPackInfoServiceImpl.class);
			
	/**
	 * 数据字典服务
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApiService;
	
	@Autowired
	private IAssPackInfoApiService assPackInfoApiService;
	
	/**
	 * 数据字典项
	 * 
	 * @param grpCd
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<KeyValueVO> getKvList(String grpCd) throws BaseException {

		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getKvList", "获取字典项组" + grpCd + "失败.ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getKvList", "获取字典项组" + grpCd + "失败,系统错误.ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}

	/**
	 * 分页查询所有
	 * @param page
	 * @return
	 */
	@Override
	@SuppressWarnings("unchecked")
	public Pager searchListPage(Pager page) throws BaseException {
		if (null == page){
			page = new Pager();
			return page;
		}
		Pager resultPager = this.assPackInfoApiService.searchListPage(page);
		List<AssPackListDTO> dto = (List<AssPackListDTO>)resultPager.getResultList();
		AssPackInfoQueryCondition condition = (AssPackInfoQueryCondition)page.getCondition();
		if(CollectionUtils.isNotEmpty(dto)){
			List<AssPackListDTO> dtoList = this.setAssPackList(dto,condition);
			resultPager.setResultList(dtoList);
		}
		return resultPager;
	}
	
	/**
	 * 设置数据字典信息
	 * @param dto
	 * @param sysCd
	 * @param orgCd
	 * @return
	 */
	private List<AssPackListDTO> setAssPackList(List<AssPackListDTO> dto, AssPackInfoQueryCondition condition){
		List<AssPackListDTO> dtoList = dto;
		List<AssPackListDTO> newDtoList = new ArrayList<AssPackListDTO>();
		//获取客户类型数据字典信息
		Map<String, String> cstTypCdList = this.sysDictionaryApiService.searchGroupToMap(condition.getSysCd(), condition.getOrgCd(), AssPackInfoConstant.ASS_PACK_INFO_CST_TYPE_CD);
		//获取所属事业部数据字典信息
		Map<String, SysDictionaryDTO> buOrgCdList = this.sysDictionaryApiService.searchGroupToObjMap(condition.getSysCd(), condition.getOrgCd(), AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
		Map<String, String> prjTypCdMap = sysDictionaryApiService.searchGroupToMapAll(condition.getSysCd(), "0000", DictionaryConstant.CODE_PRJ_TYPE_CD); //项目类型名称
		BigDecimal allTotalAmount = new BigDecimal(0);
		for(AssPackListDTO po : dtoList){
			//客户类型
			if(cstTypCdList.containsKey(po.getCstTypCd())){
				po.setCstTypNm(cstTypCdList.get(po.getCstTypCd()));
			}
			//所属事业部
			if(buOrgCdList.containsKey(po.getBuOrgCd())){
				po.setBuOrgNm(buOrgCdList.get(po.getBuOrgCd()).getCodeDesc());
			}
			//项目类型
			if (null != po.getPrjTypCd()) {
                if (prjTypCdMap.containsKey(po.getPrjTypCd())) {
                    po.setPrjTypCdNm(prjTypCdMap.get(po.getPrjTypCd()));
                }
            }
			//再融资状态
			if(("1").equals(po.getFinancingTypeCd())){
				po.setFinancingTypeNm("未占用");
			}else if(("2").equals(po.getFinancingTypeCd())){
				po.setFinancingTypeNm("预占用");
			}else if(("3").equals(po.getFinancingTypeCd())){
				po.setFinancingTypeNm("已占用");
			}else if(("4").equals(po.getFinancingTypeCd())){
				po.setFinancingTypeNm("已预约");
			}
			if(po.getFinancingAmount() != null){
				//可融资金额分换算成元
				po.setFinancingAmount(po.getFinancingAmount().divide(new BigDecimal(100)));
				newDtoList.add(po);
				//判断结果集累计可融资金额是否大于等于查询条件融资金额
				allTotalAmount = allTotalAmount.add(po.getFinancingAmount());
				if(condition.getFinancingAmount().compareTo(new BigDecimal(0)) == 1 && allTotalAmount.compareTo(condition.getFinancingAmount()) >= 0){
					return newDtoList;
				}
			}else{
				newDtoList.add(po);
			}
		}
		return newDtoList;
	}
	

	/**
	 * 添加资产包
	 * @param assPackInfo
	 * @param payRltvInfo
	 * @return
	 * @throws BaseException
	 */
	@Transactional(rollbackFor = BaseException.class)
	@Override
	public boolean add(AssPackInfoVO assPackInfo, String payRltvInfo,String termB,String termE,String mark,List<String> oldPaySchCds) throws BaseException {
		try {
			long mainId = 0;
			boolean bool = true;
			if(mark.equals("0") && null == assPackInfo.getId()){//保存资产包信息
				mainId = this.assPackInfoApiService.addAssPackInfo(AssPackInfoVOTransform.toDTO(assPackInfo));
			}else if(mark.equals("1") && null != assPackInfo.getId()){//编辑资产包信息
				bool = this.assPackInfoApiService.editAssPackInfo(AssPackInfoVOTransform.toDTO(assPackInfo));
				mainId = assPackInfo.getId();
			}else{
				mainId = assPackInfo.getId();
			}
			if(!bool){
				throw new BaseException("资产包信息添加失败！");
			}
			//解析融资筛选的支付表id
			if(mainId != 0){
				List<FncPrjPayRltvInfoVO> list = analysisPayRltvInfo(payRltvInfo, termB, termE, mainId);
//				for(FncPrjPayRltvInfoVO vo : list){
//					long id = this.assPackInfoApiService.addPayRltvInfo(FncPrjPayRltvInfoVOTransform.toDTO(vo));				
//					
//				}
				{
					int id = this.assPackInfoApiService.batchInsert(FncPrjPayRltvInfoVOTransform.toDTOList(list));
					if(StringUtils.isEmpty(id)){
						throw new BaseException("资产包信息添加失败！");
					}
				}
				//旧支付表保存
				if (oldPaySchCds!=null) {
					for (int i = 0; i < oldPaySchCds.size(); i++) {
						FncPrjPayRltvInfo2DTO dto=new FncPrjPayRltvInfo2DTO();
						dto.setAssPackId(mainId);
						dto.setPyStcd(String.valueOf(BaseConstant.IS_YESNO_YES));
						dto.setPayCode(oldPaySchCds.get(i));
						long id = this.assPackInfoApiService.addPayRltvInfo2(dto);				
						if(StringUtils.isEmpty(id)){
							throw new BaseException("资产包信息添加失败！");
						}
					}
				}
			}else{
				throw new BaseException("资产包信息添加失败！");
			}
		} catch (Exception e) {
			throw new BaseException(e.getMessage());
		}
		
		return true;
	}
	
	/**
	 * 解析融资筛选的支付表id
	 * @param payRltvInfo
	 * @param mainId
	 * @return
	 */
	private List<FncPrjPayRltvInfoVO> analysisPayRltvInfo(String payRltvInfo,String termB,String termE, long mainId){
		List<FncPrjPayRltvInfoVO> list = new ArrayList<FncPrjPayRltvInfoVO>();
		if(StringUtils.isNotEmpty(payRltvInfo) && StringUtils.isNotEmpty(mainId)){
			String[] sourceStrArray = payRltvInfo.split(",");
			String[] sourceStrArrayTermB = termB.split(",");
			String[] sourceStrArrayTermE = termE.split(",");
			for(int i = 0; i < sourceStrArray.length; i++){
				FncPrjPayRltvInfoVO vo = new FncPrjPayRltvInfoVO();
				vo.setAssPackId(mainId);
				vo.setPaySchId(Long.valueOf(sourceStrArray[i].toString()));
				if(StringUtils.isNotEmpty(sourceStrArrayTermB[i])){
					vo.setTermB(Integer.parseInt(sourceStrArrayTermB[i].toString()));
				}
				if(StringUtils.isNotEmpty(sourceStrArrayTermE[i])){
					vo.setTermE(Integer.parseInt(sourceStrArrayTermE[i].toString()));
				}
				vo.setPyStcd(String.valueOf(BaseConstant.IS_YESNO_YES));
				vo.setCrtPsnEcd(CurrentThreadContext.getCurrentUserName());
				list.add(vo);
			}
		}
		return list;
	}

	/**
	 * 数据字典项（所属事业部）
	 * 
	 * @param grpCd
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<KeyValueVO> getCodeDescList(String grpCd) throws BaseException {
		List<KeyValueVO> kvList = new ArrayList<>();
		try {
			List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(),
					CurrentThreadContext.getCurrentOrgCd(), grpCd);
			if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
				for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
					KeyValueVO keyValueVO = new KeyValueVO();
					keyValueVO.setKey(sysDictionaryDTO.getCode());
					keyValueVO.setValue(sysDictionaryDTO.getCodeDesc());
					kvList.add(keyValueVO);
				}
			}
		} catch (BaseException e) {
			BaseLogUtils.info(logger, "getCodeDescList", "获取字典项组" + grpCd + "失败.ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
		} catch (Exception e) {
			BaseLogUtils.error(logger, "getCodeDescList", "获取字典项组" + grpCd + "失败,系统错误.ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
		}
		return kvList;
	}

	/**
	 * 查询资产包信息
	 */
	@Override
	@SuppressWarnings("unchecked")
	public Pager searchPackInfoListPage(Pager page) throws BaseException {
		if (null == page){
			page = new Pager();
			return page;
		}
		Pager resultPager = this.assPackInfoApiService.searchPackInfoListPage(page);
		List<AssPackInfoDTO> dto = (List<AssPackInfoDTO>)resultPager.getResultList();
		AssPackInfoQueryCondition condition = (AssPackInfoQueryCondition)page.getCondition();
		if(CollectionUtils.isNotEmpty(dto)){
			List<AssPackInfoDTO> dtoList = this.setAssPackList(dto,condition.getSysCd(),condition.getOrgCd());
			resultPager.setResultList(dtoList);
		}
		
		return resultPager;
		
		
	}

	/**
	 * 设置数据字典信息
	 * @param dto
	 * @param sysCd
	 * @param orgCd
	 * @return
	 */
	private List<AssPackInfoDTO> setAssPackList(List<AssPackInfoDTO> dto, String sysCd, String orgCd){
		List<AssPackInfoDTO> dtoList = dto;
		//获取客户类型数据字典信息
		Map<String, String> cstTypCdList = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, AssPackInfoConstant.ASS_PACK_INFO_CST_TYPE_CD);
		//获取所属事业部数据字典信息
		Map<String, SysDictionaryDTO> buOrgCdList = this.sysDictionaryApiService.searchGroupToObjMap(sysCd, orgCd, AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
		//获取融资基数数据字典信息
		Map<String, String> fncCrdnltList = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, AssPackInfoConstant.ASS_PACK_INFO_FNC_CRDNLT);
		//获取是否
		Map<String, String> isMortgageList = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, AssPackInfoConstant.ASS_PACK_INFO_IS_MORTGAGE);
		//获取替换状态
		Map<String, String> repStList = this.sysDictionaryApiService.searchGroupToMap(sysCd, orgCd, AssPackInfoConstant.ASS_PACK_INFO_REPLACE_ST);
		for(AssPackInfoDTO po : dtoList){
			//客户类型
			if(cstTypCdList.containsKey(String.valueOf(po.getCstTypCd()))){
				po.setCstTypCdNm(cstTypCdList.get(String.valueOf(po.getCstTypCd())));
			}
			//所属事业部
			if(!("").equals(po.getBuOrgCd()) && po.getBuOrgCd() != null){
				String arr [] = po.getBuOrgCd().split(";");
				String buOrgCdNm = "";
				for(int i = 0; i < arr.length; i++){
					if(buOrgCdList.containsKey(arr[i])){
						if(("").equals(buOrgCdNm)){
							buOrgCdNm =  buOrgCdList.get(arr[i]).getCodeDesc(); 
						}else{
							buOrgCdNm += ";" + buOrgCdList.get(arr[i]).getCodeDesc(); 
						}
					}
				}
				po.setBuOrgCdNm(buOrgCdNm);
			}
			//融资基数
			if(fncCrdnltList.containsKey(String.valueOf(po.getFncCrdnlt()))){
				po.setFncCrdnltNm(fncCrdnltList.get(String.valueOf(po.getFncCrdnlt())));
			}
			//是否保险
			if(isMortgageList.containsKey(String.valueOf(po.getIsInsure()))){
				po.setIsInsureNm(isMortgageList.get(String.valueOf(po.getIsInsure())));
			}
			//是否抵押
			if(isMortgageList.containsKey(String.valueOf(po.getIsMgt()))){
				po.setIsMgtNm(isMortgageList.get(String.valueOf(po.getIsMgt())));
			}
			//替换状态
			if(repStList.containsKey(String.valueOf(po.getRepSt()))){
				po.setRepStNm(repStList.get(String.valueOf(po.getRepSt())));
			}
		}
		
		return dtoList;
	}
	
	
	/**
	 * 根据id查询资产包信息
	 * @param id
	 * @param sysCd
	 * @param orgCd
	 * @return
	 * @throws BaseException
	 */
	@Override
	public AssPackInfoVO selectById(long id, String sysCd, String orgCd) throws BaseException {
		if (StringUtils.isEmpty(id)) {
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		AssPackInfoDTO dto = this.assPackInfoApiService.selectById(id,sysCd,orgCd);
		List<AssPackInfoDTO> list = new ArrayList<AssPackInfoDTO>();
		list.add(dto);
		return AssPackInfoVOTransform.toVO(this.setAssPackList(list, sysCd, orgCd).get(0));
	}

	/**
	 * 分页查询资产包所有
	 * @param page
	 * @return
	 */
	@Override
	public Pager searchPaySchInfoList(Pager page) throws BaseException {
		if(null == page){
			return page;
		}
		return this.searchListPage(page);
		//return this.assPackInfoApiService.searchListPage(page);
	}

	/**
	 * 删除资产包
	 * @param payRltvInfo
	 * @return
	 * @throws BaseException
	 */
	@Override
	public boolean deletePayRltvInfo(String payRltvInfo, String assPackId) throws BaseException {
		if(StringUtils.isNotEmpty(payRltvInfo)){
			FncPrjPayRltvInfoVO vo = new FncPrjPayRltvInfoVO();
			String[] sourceStrArray = payRltvInfo.split(",");
			for(int i = 0; i < sourceStrArray.length; i++){
				vo.setPaySchId(Long.valueOf(sourceStrArray[i].toString()));
				vo.setPyStcd(String.valueOf(BaseConstant.IS_YESNO_NO));
				vo.setAssPackId(Long.valueOf(assPackId));
				long id = this.assPackInfoApiService.deletePayRltvInfo(FncPrjPayRltvInfoVOTransform.toDTO(vo));				
				if(StringUtils.isEmpty(id)){
					throw new BaseException("资产包信息添加失败！");
				}
			}
		}
		return true;
	}

	/**
	 * 根据资产包id及筛选条件查询所有资产包信息
	 * @param condition
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<AssPackListVO> searchAssPackList(AssPackInfoQueryCondition condition) throws BaseException {
		if(null == condition){
			throw new BaseException("资产包查询条件不能为空！");
		}
		AssPackInfoVO assPackInfoVO = this.selectById(condition.getId(), condition.getSysCd(), condition.getOrgCd());
		AssPackInfoQueryCondition assPackListCondition = new AssPackInfoQueryCondition();
		if(null == assPackInfoVO){
			return null;
		}
		assPackListCondition.setBuOrgCd(assPackInfoVO.getBuOrgCd());
		assPackListCondition.setCstTypCd(String.valueOf(assPackInfoVO.getCstTypCd()));
		if(null != condition.getStdt()){
			assPackListCondition.setEddt(condition.getEddt());
		}else{
			assPackListCondition.setEddt(assPackInfoVO.getEddt());
		}
		assPackListCondition.setEdDtQ(assPackInfoVO.getFlDateE());
		assPackListCondition.setFncCrdnlt(condition.getFncCrdnlt());
		assPackListCondition.setIsInsurance(String.valueOf(assPackInfoVO.getIsInsure()));
		assPackListCondition.setIsMortgage(String.valueOf(assPackInfoVO.getIsMgt()));
		assPackListCondition.setLeaseTermMaxQ(assPackInfoVO.getLeaTermE());
		assPackListCondition.setLeaseTermMinQ(assPackInfoVO.getLeaTermB());
		assPackListCondition.setOrgCd(condition.getOrgCd());
		assPackListCondition.setOvdDaysMax(assPackInfoVO.getOdDateE());
		assPackListCondition.setOvdDaysMin(assPackInfoVO.getOdDateB());
		if(null != condition.getStdt()){
			assPackListCondition.setStdt(condition.getStdt());
		}else{
			assPackListCondition.setStdt(assPackInfoVO.getStdt());
		}
		assPackListCondition.setStDtQ(assPackInfoVO.getFlDateB());;
		assPackListCondition.setSurplusLeaseTermMaxQ(assPackInfoVO.getReLeaTermE());
		assPackListCondition.setSurplusLeaseTermMinQ(assPackInfoVO.getReLeaTermB());
		assPackListCondition.setSysCd(condition.getSysCd());
		assPackListCondition.setId(condition.getId());
		Pager page = new Pager();
		page.setCurrentPage(1);
		page.setEveryPage(100000);
		page.setCondition(assPackListCondition);
		Pager resultPager = this.searchListPage(page);
		List<AssPackListDTO> dtoList = (List<AssPackListDTO>)resultPager.getResultList();
		List<AssPackListVO> voList = AssPackListVOTransform.toVOList(dtoList);
		return voList;
	}

	/**
	 * 根据资产包ID获取融资项目与支付关联表信息
	 * @param id
	 * @return
	 */
	@Override
	public List<FncPrjPayRltvInfoVO> selectByAssPackId(Long id) throws BaseException {
		if(null == id){
			return null;
		}
		List<FncPrjPayRltvInfoDTO> dtoList = assPackInfoApiService.selectByAssPackId(id);
		return FncPrjPayRltvInfoVOTransform.toVOList(dtoList);
	}

	/**
	 * 分页查询资产包下的支付表信息
	 * @param page
	 * @return
	 */
	@Override
	@SuppressWarnings("unchecked")
	public Pager searchReplaceListPage(Pager page) throws BaseException {
		if (null == page){
			page = new Pager();
			return page;
		}
		Pager resultPager = this.assPackInfoApiService.searchReplaceListPage(page);
		List<AssPackListDTO> dto = (List<AssPackListDTO>)resultPager.getResultList();
		AssPackInfoReplaceQueryCondition condition = (AssPackInfoReplaceQueryCondition)page.getCondition();
		if(CollectionUtils.isNotEmpty(dto)){
			List<AssPackListDTO> dtoList = this.setAssPackList(dto,condition);
			resultPager.setResultList(dtoList);
		}
		return resultPager;
		//return this.assPackInfoApiService.searchReplaceListPage(page);
	}
	
	/**
	 * 设置数据字典信息
	 * @param dto
	 * @param sysCd
	 * @param orgCd
	 * @return
	 */
	private List<AssPackListDTO> setAssPackList(List<AssPackListDTO> dto, AssPackInfoReplaceQueryCondition condition){
		List<AssPackListDTO> dtoList = dto;
		List<AssPackListDTO> newDtoList = new ArrayList<AssPackListDTO>();
		//获取客户类型数据字典信息
		Map<String, String> cstTypCdList = this.sysDictionaryApiService.searchGroupToMap(condition.getSysCd(), condition.getOrgCd(), AssPackInfoConstant.ASS_PACK_INFO_CST_TYPE_CD);
		//获取所属事业部数据字典信息
		Map<String, SysDictionaryDTO> buOrgCdList = this.sysDictionaryApiService.searchGroupToObjMap(condition.getSysCd(), condition.getOrgCd(), AssPackInfoConstant.ASS_PACK_INFO_BU_ORG_CD);
		for(AssPackListDTO po : dtoList){
			//客户类型
			if(cstTypCdList.containsKey(po.getCstTypCd())){
				po.setCstTypNm(cstTypCdList.get(po.getCstTypCd()));
			}
			//所属事业部
			if(buOrgCdList.containsKey(po.getBuOrgCd())){
				po.setBuOrgNm(buOrgCdList.get(po.getBuOrgCd()).getCodeDesc());
			}
			//再融资状态
			if(("1").equals(po.getFinancingTypeCd())){
				po.setFinancingTypeNm("未占用");
			}else if(("2").equals(po.getFinancingTypeCd())){
				po.setFinancingTypeNm("预占用");
			}else if(("3").equals(po.getFinancingTypeCd())){
				po.setFinancingTypeNm("已占用");
			}
			if(po.getFinancingAmount() != null){
				//可融资金额分换算成元
				po.setFinancingAmount(po.getFinancingAmount().divide(new BigDecimal(100)));
				newDtoList.add(po);
			}else{
				newDtoList.add(po);
			}
		}
		return newDtoList;
	}

	/**
	 * 添加替换资产包
	 * @param vo
	 * @return
	 * @throws BaseException
	 */
	@Transactional(rollbackFor = BaseException.class)
	@Override
	public long replaceAndAddAssPackInfo(FncPrjPayRltvInfoReplaceVO vo) throws BaseException {
		long repId = 0;
		try {
			//组装替换的assPackInfo记录信息
			AssPackInfoReplaceVO coverAssPackInfVO = this.assembleAssPackInfoVO(vo.getAssPackId());
			//保存替换的assPackInfo记录信息
			repId = assPackInfoApiService.addCoverAssPackInfo(AssPackInfoReplaceVOTransform.toDTO(coverAssPackInfVO));
			if(StringUtils.isEmpty(repId)){
				throw new BaseException("资产包支付信息替换失败");
			}
			if(StringUtils.isNotEmpty(vo.getCoverPayRltvInfo())){
				//组装被替换支付表关系
				FncPrjPayRltvInfoReplaceVO coverFncVO = vo;
				coverFncVO.setRepId(repId);
				List<FncPrjPayRltvInfoReplaceDTO> coverFncPrjPayRltvInfoList = this.assembleFncPrjPayRltvInfoDTO(coverFncVO, 0);
				//批量保存
				assPackInfoApiService.addAllCoverPayInfo(coverFncPrjPayRltvInfoList);
			}
			if (StringUtils.isNotEmpty(vo.getReplacePayRltvInfo())) {
				//组装替换支付表关系
				FncPrjPayRltvInfoReplaceVO replaceFncVO = vo;
				if(StringUtils.isEmpty(repId)){
					throw new BaseException("资产包支付信息替换失败");
				}
				replaceFncVO.setRepId(repId);
				List<FncPrjPayRltvInfoReplaceDTO> replaceFncPrjPayRltvInfoList = this.assembleFncPrjPayRltvInfoDTO(replaceFncVO, 1);
				//批量保存
				assPackInfoApiService.addAllCoverPayInfo(replaceFncPrjPayRltvInfoList);
			}
			
			//更新原资产包支付表替换状态
			this.assPackInfoApiService.modifyAssPackRepSt(vo.getAssPackId(),1);
			
		} catch (Exception e) {
			throw new BaseException("资产包支付信息替换失败");
		}
		return repId;
	}
	
	/**
	 * 组装资产包VO
	 * @param assPackId
	 * @return
	 */
	private AssPackInfoReplaceVO assembleAssPackInfoVO(long assPackId){
		AssPackInfoReplaceVO coverVO = new AssPackInfoReplaceVO();
		coverVO.setAssPackId(assPackId);
		coverVO.setRepSt(1);
		coverVO.setIsValid(BaseConstant.IS_YESNO_YES);
		coverVO.setIsDel(BaseConstant.IS_YESNO_NO);
		return coverVO;
	}
	
	/**
	 * 组装资产包与支付表关系DTO
	 * @param dto
	 * @param repSt
	 * @return
	 */
	private List<FncPrjPayRltvInfoReplaceDTO> assembleFncPrjPayRltvInfoDTO(FncPrjPayRltvInfoReplaceVO vo, Integer repSt){
		List<FncPrjPayRltvInfoReplaceDTO> coverDTOList = new ArrayList<FncPrjPayRltvInfoReplaceDTO>();
			String[] sourceStrArray = null;
			String[] sourceStrArrayTermB = null;
			String[] sourceStrArrayTermE = null;
			String[] financingAmount = null;
			if(repSt == 0){
				if(StringUtils.isNotEmpty(vo.getCoverPayRltvInfo())){
					sourceStrArray = vo.getCoverPayRltvInfo().split(",");
					sourceStrArrayTermB = vo.getCoverTermB().split(",");
					sourceStrArrayTermE = vo.getCoverTermE().split(",");
					financingAmount = vo.getCoverFinancingAmount().split(",");
				}
			}else{
				if(StringUtils.isNotEmpty(vo.getReplacePayRltvInfo())){
					sourceStrArray = vo.getReplacePayRltvInfo().split(",");
					sourceStrArrayTermB = vo.getReplaceTermB().split(",");
					sourceStrArrayTermE = vo.getReplaceTermE().split(",");
					financingAmount = vo.getReplaceFinancingAmount().split(",");
				}	
			}
			for(int i = 0; i < sourceStrArray.length; i++){
				FncPrjPayRltvInfoReplaceDTO coverDTO = new FncPrjPayRltvInfoReplaceDTO();
				coverDTO.setAssPackId(vo.getAssPackId());
				coverDTO.setCrtPsnEcd(CurrentThreadContext.getCurrentUserName());
				if(StringUtils.isNotEmpty(sourceStrArray[i])){
					coverDTO.setPaySchId(Long.valueOf(sourceStrArray[i]));
				}
				if(StringUtils.isNotEmpty(sourceStrArrayTermB[i])){
					coverDTO.setTermB(Integer.parseInt(sourceStrArrayTermB[i]));
				}else{
					coverDTO.setTermB(0);
				}
				if(StringUtils.isNotEmpty(sourceStrArrayTermE[i])){
					coverDTO.setTermE(Integer.parseInt(sourceStrArrayTermE[i]));
				}else{
					coverDTO.setTermE(0);
				}
				if(StringUtils.isNotEmpty(financingAmount[i])){
					coverDTO.setFinancingAmount(new BigDecimal(financingAmount[i]).multiply(new BigDecimal(100)));
				}else{
					coverDTO.setFinancingAmount(new BigDecimal(0));
				}
				coverDTO.setRepType(repSt);
				coverDTO.setPyStcd(vo.getPyStcd());
				coverDTO.setRepId(vo.getRepId());
				coverDTO.setOperationDate(new Date());
				coverDTOList.add(coverDTO);
			}
		return coverDTOList;
	}

	@Override
	public DataResultDTO addFlowStart(FlowStartParamsDTO flowStartParamsDTO) throws BaseException {
		if(StringUtils.isEmpty(flowStartParamsDTO.getCrtUsrId()) || StringUtils.isEmpty(flowStartParamsDTO.getBusinessKey())){
			BaseLogUtils.info(logger, "addFlowStart", "用户ID和业务数据主键必须要存在!",CurrentThreadContext.getCurrentUserName());
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, "用户ID和业务数据主键必须要存在!");
		}
		return this.assPackInfoApiService.addFlowStart(flowStartParamsDTO);
	}

	/**
     * 根据资产包id查询资产包记录"预替换"关联的支付信息
     * @param assPackId
     * @return
     * @throws BaseException
     */
	@Override
	public List<FncPrjPayRltvInfoReplaceDTO> getPayIdsByAssPackId(Long assPackId) throws BaseException {
		return this.assPackInfoApiService.getPayIdsByAssPackId(assPackId);
	}

	/**
	 * 替换资产包记录查询
	 * @param assPackId
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<RecordReplaceAssPackVO> recordReplaceAssPackInfo(Long assPackId) throws BaseException {
		List<RecordReplaceAssPackVO> recordReplaceAssPackList = new ArrayList<RecordReplaceAssPackVO>();
		//根据资产包id查询资产包"预替换"替换记录
		List<FncPrjPayRltvInfoReplaceDTO> preSubstitutionList = this.assPackInfoApiService.getPayIdsByAssPackId(assPackId);
		//根据资产包id查询资产包"已替换"替换记录
		List<FncPrjPayRltvInfoReplaceDTO> replacedList = this.assPackInfoApiService.getReplacePayIdsByAssPackId(assPackId);
		//根据资产包id查询资产包"已替换"替换资产包信息
		AssPackInfoReplaceDTO dto = new AssPackInfoReplaceDTO();
		dto.setAssPackId(assPackId);
		dto.setRepSt(AssPackInfoMst.REPLACED.getKey());
		List<AssPackInfoReplaceDTO> assPackInfoReplaceDTOList = this.assPackInfoApiService.getAssPackInfoReplaceList(dto);
		//组装"预替换"记录信息
		RecordReplaceAssPackVO preSubstitutionVO = assembleReplacementRecord(preSubstitutionList);
		if(preSubstitutionVO != null){
			recordReplaceAssPackList.add(preSubstitutionVO);
		}
		//组装"已替换"记录信息
		if(assPackInfoReplaceDTOList != null){
			for(AssPackInfoReplaceDTO dtoList : assPackInfoReplaceDTOList){
				RecordReplaceAssPackVO replacedVO = assembleReplacedRecord(replacedList, dtoList.getId());
				if(replacedVO != null){
					recordReplaceAssPackList.add(replacedVO);
				}
			}
		}
		return recordReplaceAssPackList;
	}

	/**
	 * 根据资产包id查询资产包记录"已替换"关联的支付信息
	 * @param assPackId
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<FncPrjPayRltvInfoReplaceDTO> getReplacePayIdsByAssPackId(Long assPackId) throws BaseException {
		if(assPackId == 0){
			return null;
		}
		return this.assPackInfoApiService.getReplacePayIdsByAssPackId(assPackId);
	}
	
	/**
	 * 组装"预替换"替换记录信息
	 * @param list
	 * @return
	 */
	private RecordReplaceAssPackVO assembleReplacementRecord(List<FncPrjPayRltvInfoReplaceDTO> list){
		if(list.isEmpty()){
			return null;
		}
		RecordReplaceAssPackVO recordReplaceAssPackVO = new RecordReplaceAssPackVO();
		String oldPayIds = "";
		String replacePayIds = "";
		String repTypeNm = "预替换";
		BigDecimal oldFinancingAmount = new BigDecimal(0.00);
		BigDecimal replaceFinancingAmount = new BigDecimal(0.00);
		for(FncPrjPayRltvInfoReplaceDTO dto : list){
				if(dto.getRepType() == 0){
					if(StringUtils.isEmpty(oldPayIds)){
						oldPayIds = String.valueOf(dto.getPaySchId());
					}else{
						oldPayIds += "," + String.valueOf(dto.getPaySchId());
					}
				}else{
					if(StringUtils.isEmpty(replacePayIds)){
						replacePayIds = String.valueOf(dto.getPaySchId());
					}else{
						replacePayIds += "," + String.valueOf(dto.getPaySchId());
					}
				}
			if(dto.getFinancingAmount() != null){
				if(dto.getRepType() == 0){
					oldFinancingAmount = oldFinancingAmount.add(dto.getFinancingAmount());
				}else{
					replaceFinancingAmount = replaceFinancingAmount.add(dto.getFinancingAmount());
				}
			}
		}
		recordReplaceAssPackVO.setCrtPsnEcd(list.get(0).getCrtPsnEcd());
		recordReplaceAssPackVO.setOldPayId(oldPayIds);
		recordReplaceAssPackVO.setReplacePayId(replacePayIds);
		recordReplaceAssPackVO.setFinancingAmount(oldFinancingAmount.divide(new BigDecimal(100)));
		recordReplaceAssPackVO.setReplaceFinancingAmount(replaceFinancingAmount.divide(new BigDecimal(100)));
		recordReplaceAssPackVO.setOperationDate(list.get(0).getOperationDate());
		recordReplaceAssPackVO.setRepTypeNm(repTypeNm);
		return recordReplaceAssPackVO;
	}
	
	/**
	 * 组装"已替换"替换记录信息
	 * @param list
	 * @param repId
	 * @return
	 */
	private RecordReplaceAssPackVO assembleReplacedRecord(List<FncPrjPayRltvInfoReplaceDTO> list, Long repId){
		if(list.isEmpty()){
			return null;
		}
		RecordReplaceAssPackVO recordReplaceAssPackVO = new RecordReplaceAssPackVO();
		String oldPayIds = "";
		String replacePayIds = "";
		String repTypeNm = "已替换";
		BigDecimal oldFinancingAmount = new BigDecimal(0.00);
		BigDecimal replaceFinancingAmount = new BigDecimal(0.00);
		String crtPsnEcd = "";
		Date operationDate = new Date();
		for(FncPrjPayRltvInfoReplaceDTO dto : list){
			if(dto.getRepId().equals(repId)){
				if(dto.getRepType() == 0){
					if(StringUtils.isEmpty(oldPayIds)){
						oldPayIds = String.valueOf(dto.getPaySchId());
					}else{
						oldPayIds += "," + String.valueOf(dto.getPaySchId());
					}
				}else{
					if(StringUtils.isEmpty(replacePayIds)){
						replacePayIds = String.valueOf(dto.getPaySchId());
					}else{
						replacePayIds += "," + String.valueOf(dto.getPaySchId());
					}
				}
				if(dto.getFinancingAmount() != null){
					if(dto.getRepType() == 0){
						oldFinancingAmount = oldFinancingAmount.add(dto.getFinancingAmount());
					}else{
						replaceFinancingAmount = replaceFinancingAmount.add(dto.getFinancingAmount());
					}
				}
				crtPsnEcd = dto.getCrtPsnEcd();
				operationDate = dto.getOperationDate();
			}
		}
		recordReplaceAssPackVO.setCrtPsnEcd(crtPsnEcd);
		recordReplaceAssPackVO.setOldPayId(oldPayIds);
		recordReplaceAssPackVO.setReplacePayId(replacePayIds);
		recordReplaceAssPackVO.setFinancingAmount(oldFinancingAmount.divide(new BigDecimal(100)));
		recordReplaceAssPackVO.setReplaceFinancingAmount(replaceFinancingAmount.divide(new BigDecimal(100)));
		recordReplaceAssPackVO.setOperationDate(operationDate);
		recordReplaceAssPackVO.setRepTypeNm(repTypeNm);
		return recordReplaceAssPackVO;
	}

	/**
	 * 修改资产包替换记录信息
	 * @param vo
	 * @return
	 * @throws BaseException
	 */
	@Override
	public boolean modifyReplaceAssPackInfo(FncPrjPayRltvInfoReplaceVO vo) throws BaseException {
		boolean bool = true;
		try {
			//根据资产包id查询资产包"预替换"的替换记录
			AssPackInfoReplaceVO assPackInfoReplace = new AssPackInfoReplaceVO();
			assPackInfoReplace.setAssPackId(vo.getAssPackId());
			assPackInfoReplace.setRepSt(AssPackInfoMst.SUBSTITUTION.getKey());
			assPackInfoReplace.setId(vo.getRepId());
			AssPackInfoReplaceDTO assPackInfoReplaceDTO = this.assPackInfoApiService.getAssPackInfoReplace(AssPackInfoReplaceVOTransform.toDTO(assPackInfoReplace));
			List<FncPrjPayRltvInfoReplaceDTO> coverFncPrjPayRltvInfoList = new ArrayList<FncPrjPayRltvInfoReplaceDTO>();
			if(StringUtils.isNotEmpty(vo.getCoverPayRltvInfo())){
				//组装被替换支付表关系
				FncPrjPayRltvInfoReplaceVO coverFncVO = vo;
				coverFncVO.setRepId(assPackInfoReplaceDTO.getId());
				coverFncPrjPayRltvInfoList = this.assembleFncPrjPayRltvInfoDTO(coverFncVO, 0);
			}
			//组装替换支付表关系
			FncPrjPayRltvInfoReplaceVO replaceFncVO = vo;
			replaceFncVO.setRepId(assPackInfoReplaceDTO.getId());
			List<FncPrjPayRltvInfoReplaceDTO> replaceFncPrjPayRltvInfoList = this.assembleFncPrjPayRltvInfoDTO(replaceFncVO, 1);
			
			//删除原记录关系
			FncPrjPayRltvInfoReplaceDTO fncPrjPayRltvInfoReplaceDTO = new FncPrjPayRltvInfoReplaceDTO();
			fncPrjPayRltvInfoReplaceDTO.setAssPackId(vo.getAssPackId());
			fncPrjPayRltvInfoReplaceDTO.setPyStcd("0");
			fncPrjPayRltvInfoReplaceDTO.setRepId(assPackInfoReplaceDTO.getId());
			bool = assPackInfoApiService.deleteFncPrjPayRltvInfoReplaceInfo(fncPrjPayRltvInfoReplaceDTO);
			if(!bool){
				return bool;
			}
			if(!coverFncPrjPayRltvInfoList.isEmpty()){
				//批量保存被替换的资产包和支付表关系
				assPackInfoApiService.addAllCoverPayInfo(coverFncPrjPayRltvInfoList);
			}
			//批量保存替换的资产包和支付表关系
			assPackInfoApiService.addAllCoverPayInfo(replaceFncPrjPayRltvInfoList);
		} catch (Exception e) {
			bool = false;
			throw new BaseException("资产包支付信息替换失败");
		}
		return bool;
	}

	/**
	 * 查询资产包替换记录信息
	 * @param vo
	 * @return
	 * @throws BaseException
	 */
	@Override
	public AssPackInfoReplaceDTO getAssPackInfoReplace(AssPackInfoReplaceDTO dto) throws BaseException {
		if(dto == null){
			return null;
		}
		return this.assPackInfoApiService.getAssPackInfoReplace(dto);
	}

	/**
	 * 删除资产包与支付关系表记录
	 * @param dto
	 * @return 
	 * @throws BaseException
	 */
	@Override
	public boolean deleteFncPrjPayRltvInfoReplaceInfo(FncPrjPayRltvInfoReplaceDTO dto) throws BaseException {
		if(dto == null){
			return false;
		}
		return this.assPackInfoApiService.deleteFncPrjPayRltvInfoReplaceInfo(dto);
	}

	/**
	 * 根据资产包id查询资产包替换记录信息
	 * @param dto
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<AssPackInfoReplaceDTO> getAssPackInfoReplaceList(AssPackInfoReplaceDTO dto) throws BaseException {
		if(dto == null){
			return null;
		}
		return this.assPackInfoApiService.getAssPackInfoReplaceList(dto);
	}

	/**
	 * 获取资产包占用详情
	 * @param vo
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<AssPackOccupyDetailVO> getAssPackOccupyDetail(AssPackListVO vo) throws BaseException {
		//根据支付ID和支付编号获取支付信息
		List<AssPackOccupyDetailVO> list = new ArrayList<AssPackOccupyDetailVO>();
		for(int i = vo.getMinPd(); i <= vo.getMaxPd(); i++){
			AssPackOccupyDetailVO assPackOccupy = new AssPackOccupyDetailVO(); 
			AssPackOccupyDetailDTO AssPackOccupyDTO = new AssPackOccupyDetailDTO();
			AssPackOccupyDTO.setPayId(vo.getId());
			AssPackOccupyDTO.setNumberPd(i);
			AssPackOccupyDTO.setOccupyType(1);		//已占用
			List<FncPrjPayRltvInfoDTO> payRltvInfoList = this.assPackInfoApiService.getAssPackOccupy(AssPackOccupyDTO);
			if(payRltvInfoList.isEmpty() || ("").equals(payRltvInfoList)){
				AssPackOccupyDTO.setOccupyType(2);		//预占用
				List<FncPrjPayRltvInfoDTO> payRltvInfoList2 = this.assPackInfoApiService.getAssPackOccupy(AssPackOccupyDTO);
				if(!payRltvInfoList2.isEmpty() && !("").equals(payRltvInfoList2)){
					assPackOccupy = getRltvInfo(payRltvInfoList2);
					assPackOccupy.setNumberPd(i);
					assPackOccupy.setOccupyType(2);
					assPackOccupy.setOccupyTypeNM("预占用");
					assPackOccupy.setPayId(vo.getId());
				}
			}else{
				assPackOccupy = getRltvInfo(payRltvInfoList);
				assPackOccupy.setNumberPd(i);
				assPackOccupy.setOccupyType(1);
				assPackOccupy.setOccupyTypeNM("已占用");
				assPackOccupy.setPayId(vo.getId());
			}
			if(assPackOccupy.getPayId() != null && assPackOccupy.getPayId() != 0){
				list.add(assPackOccupy);
			}
		}
		return list;
	}
	
	/**
	 * 获取项目编号和项目名称
	 * @param payRltvInfoList
	 * @return
	 */
	private AssPackOccupyDetailVO getRltvInfo(List<FncPrjPayRltvInfoDTO> payRltvInfoList){
		AssPackOccupyDetailVO assPackOccupyDetailVO = new AssPackOccupyDetailVO();
		String fncPrjId = "";
		String fncPrjNm = "";
		for(FncPrjPayRltvInfoDTO rltvInfo : payRltvInfoList){
			if(("").equals(fncPrjId)){
				fncPrjId = rltvInfo.getFncPrjId();
				fncPrjNm = rltvInfo.getFncPrjNm();
			}else{
				fncPrjId += "," + rltvInfo.getFncPrjId();
				fncPrjNm += "," + rltvInfo.getFncPrjNm();
			}
		}
		assPackOccupyDetailVO.setFncPrjId(fncPrjId);
		assPackOccupyDetailVO.setFncPrjNm(fncPrjNm);
		return assPackOccupyDetailVO;
	}

	/**
	 * 资产包复制
	 * @param assPackId
	 * @param assPackNm
	 * @return
	 * @throws BaseException
	 */
	@Override
	public boolean copyAssPackInfo(String assPackId, String assPackNm) throws BaseException {
		//根据资产包id查询资产包信息
		AssPackInfoDTO assPackInfoDTO = this.assPackInfoApiService.selectById(Long.valueOf(assPackId), CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentOrgCd());
		//根据资产包id查询资产包和支付id关系表信息
		List<FncPrjPayRltvInfoDTO> dtoList = this.assPackInfoApiService.selectByAssPackId(Long.valueOf(assPackId));
		if(assPackInfoDTO == null){
			return false;
		}
		
		//保存资产包信息
		assPackInfoDTO.setAssPackNm(assPackNm);
		long mainId = this.assPackInfoApiService.addAssPackInfo(assPackInfoDTO);
		//保存资产包和支付id关系表信息
		if(mainId != 0){
			if(dtoList!=null){
				for(FncPrjPayRltvInfoDTO dto : dtoList){
					dto.setAssPackId(mainId);
				}
				int id = this.assPackInfoApiService.batchInsert(dtoList);				
				if(StringUtils.isEmpty(id)){
					throw new BaseException("资产包信息添加失败！");
				}
			}
			List<FncPrjPayRltvInfo2DTO> oldPaySchCds=this.assPackInfoApiService.selectOldByAssPackId(Long.valueOf(assPackId));
			//旧支付表保存
			if (oldPaySchCds!=null) {
				for (int i = 0; i < oldPaySchCds.size(); i++) {
					FncPrjPayRltvInfo2DTO dto=oldPaySchCds.get(i);
					dto.setAssPackId(mainId);
					long id = this.assPackInfoApiService.addPayRltvInfo2(dto);				
					if(StringUtils.isEmpty(id)){
						throw new BaseException("资产包信息添加失败！");
					}
				}
			}
		}else{
			throw new BaseException("资产包信息添加失败！");
		}
		return true;
	}

	/**
	 * 更新再融资状态支付期数占用区间
	 * @param po
	 * @return
	 * @throws BaseException
	 */
	@Override
	public int updatePayRltvInfo(FncPrjPayRltvInfoDTO dto) throws BaseException {
		if(dto == null){
			return 0;
		}
		return this.assPackInfoApiService.updatePayRltvInfo(dto);
	}
	/**
	 * 查询资产包关联支付表信息 旧支付表
	 * @param dto
	 * @return
	 * @throws BaseException
	 * 2018年2月12日 
	 * lxb
	 */
	@Override
	public List<FncPrjPayRltvInfo2DTO> selectOldByAssPackId(Long id) throws BaseException {
		return this.assPackInfoApiService.selectOldByAssPackId(id);
		
	}

	@Override
	public boolean deletePayRltvInfoAll(Long assPackId) throws BaseException {
		// TODO Auto-generated method stub
		if( this.assPackInfoApiService.deletePayRltvInfoAll(assPackId)>0){
			return true;
		}else {
			return false;
		}
	}
	
	/**
	 * 不分页查询所有资产包列表
	 * @param condition
	 * @return
	 */
	@Override
	public List<AssPackListDTO> searchList(AssPackInfoQueryCondition condition) throws BaseException {
		List<AssPackListDTO> dto = this.assPackInfoApiService.searchList(condition);
		if(CollectionUtils.isNotEmpty(dto)){
			List<AssPackListDTO> dtoList = this.setAssPackList(dto,condition);
			return dtoList;
		}else{
			return dto;
		}
	}
	/**
	 *    逾期天数大于30天的支付表的逾期金额总和 
	 *    逾期天数大于90天的支付表的逾期金额总和
	 * @param ASS_PACK_ID 资产包ID
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<Map<String, Object>>  getOvdAmtSumByAssPackId(String assPackIdstr) throws BaseException {
		if(StringUtils.isNotBlank(assPackIdstr)){
			return this.assPackInfoApiService.getOvdAmtSumByAssPackId(assPackIdstr);
		}
		return null;
	}
	/**
	 *     资产包总的敞口（剩余租金）
	 * @param ASS_PACK_ID 资产包ID payDate提款管理 到账时间
	 * @return
	 * @throws BaseException
	 */
	@Override
	public List<Map<String, Object>>  getSurplusRentByAssPackId(String assPackIdstr,String transtm) throws BaseException {
		if(StringUtils.isNotBlank(assPackIdstr) && StringUtils.isNotBlank(transtm)){
			return this.assPackInfoApiService.getSurplusRentByAssPackId(assPackIdstr,transtm);
		}
		return null;
	}
	
	
	/**
	 * 抵押记录数据
	 * @return
	 */
	public Pager mortgageList(Pager Page) throws BaseException {
		return this.assPackInfoApiService.mortgageList(Page);
	}
	
}
